package com.zxjbyte.yiyi.framework.common.util;

import cn.hutool.core.date.LocalDateTimeUtil;
import lombok.experimental.UtilityClass;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * 扩展hutool的LocalDateTimeUtil
 *
 * @Author zhangxingjia
 * @Date 2023/6/29 10:51
 * @Version: 1.0
 */
@UtilityClass
public class LocalDateTimeXUtil extends LocalDateTimeUtil {

    /**
     * 转换成 date
     *
     * @param dateTime LocalDateTime
     * @return Date
     */
    public Date toDate(LocalDateTime dateTime) {
        return Date.from(LocalDateTimeXUtil.toInstant(dateTime));
    }

    /**
     * 时间转 Instant
     *
     * @param dateTime 时间
     * @return Instant
     */
    public Instant toInstant(LocalDateTime dateTime) {
        return dateTime.atZone(ZoneId.systemDefault()).toInstant();
    }
}
